package com.seari.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.seari.bean.RlEventMaintenanceRecord;
import com.seari.mapper.RlEventMaintenanceRecordMapper;
import com.seari.pojo.MessageBean;
import com.seari.service.RlEventMaintenanceRecordService;

/**
 * Created by 98383 on 2019/5/7.
 */
@Service
public class RlEventMaintenanceRecordServiceImpl implements RlEventMaintenanceRecordService{
    @Resource
    RlEventMaintenanceRecordMapper rlEventMaintenanceRecordMapper;
    @Override
    public MessageBean RlEventMaintenanceRecordList(Integer taskNo,Integer start,Integer limit) {
        MessageBean message = new MessageBean("0",null,"成功");
        int q=(start - 1) * limit;
        List<RlEventMaintenanceRecord> list=rlEventMaintenanceRecordMapper.selectList(taskNo,q,limit);
        List<RlEventMaintenanceRecord> count=rlEventMaintenanceRecordMapper.selectCount(taskNo);
        for(RlEventMaintenanceRecord rlEventMaintenanceRecord:list){
            rlEventMaintenanceRecord.setcT(stampToDate(rlEventMaintenanceRecord.getCreateTime()));
//            rlEventMaintenanceRecord.setuT(stampToDate(rlEventMaintenanceRecord.getUpdatedTime()));
            rlEventMaintenanceRecord.setmD(stampToDate(rlEventMaintenanceRecord.getMaintenanceDate()));
        }
        Map<String,Object> map=new HashMap<>();
        map.put("list",list);
        map.put("count",count.size());
        message.setData(map);
        return message;
    }

    /*
     * 将时间戳转换为时间
     */
    public static String stampToDate(Date date){
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        res = simpleDateFormat.format(date);
        return res;
    }
}
